/**
 * 
 */
package edu.hawaii.duedates.library;

import com.meterware.httpunit.WebConversation;

/**
 * This interface is implements by all libraries added to DueDates.  
 * Each lender has its own way of logging in and getting information.
 * So each lender by contract need to have login and getInfo method.
 * 
 * @author John Ly
 * @author John Zhou
 */
public class Lender {
  /**
   * Attempt to login to specific library.
   * 
   * @param id The user ID needed by the site
   * @param password The password that corresponds to that account
   * @return The WebConversation instance after successful login.
   * @throws Exception If login was not successful with these credentials.
   */
  public WebConversation login(String id, String password) throws Exception {
    System.out.println("Library needs it's own specific login method");
    return new WebConversation();
  }
  
  /**
   * Given a logged in user, provides info about their checked out items.
   * 
   * @param id The user ID for the site.
   * @param password The password that corresponds to that account
   * @return A String containing information about their items
   * @throws Exception If problems occur parsing the site pages.
   */
  public String getInfo(String id, String password) throws Exception {
    System.out.println("Library needs it's own specific login method");
    return "";
  }
  
  /**
   * Converts due date and book title into a formatted string. 
   * Method should be used to create output string for all materials
   * for consistency.
   * 
   * @param duedate The due date of when the title is due
   * @param title The title of the book
   * @return A String containing the book info in proper output format
   */
  public String toFormattedString(String duedate, String title) {
    String format = " %1$-25.25s | %2$-60.60s\n";
    if (title.length() <= 50) {
      return String.format(format, duedate, title);
    }
    
    String output = String.format(format, duedate, title);
    int charsPerRow = 60;
    int rowsForTitle = title.length() / charsPerRow;
    if (title.length() % charsPerRow != 0) {
      rowsForTitle++;
    }    
    for (int i = 1; i < rowsForTitle; i++) {
      output = output.concat(String.format(format, "", title.substring(charsPerRow * i)));
    }
    return output;
  }
}
